package com.platform.modules.app.controller;


import com.platform.common.utils.RestResponse;
import com.platform.modules.mall.location.utils.LocationUtil;
import com.platform.modules.mall.service.MallBranchService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

@Api(tags = "AppActivityController|支行模块")
@RestController
@RequestMapping("/app/branch")
public class AppBranchController extends AppBaseController{

    @Resource
    private MallBranchService branchService;

    @GetMapping("getList")
    public RestResponse getBranchList(@RequestParam Map<String, Object> map){
        if(map.get("location") != null){
            Object range = map.get("range");
            try {
                String[] location = ((String) map.get("location")).split(",");
                // 注意 mysql8.0 以上 配合新的距离计算函数 此处需要换成 0，1  （纬度，经度）  旧版本使用 1，0 （经度，纬度）
                map.put("location", location[0] + " " + location[1]);
                if(range != null){
                    map.put("scope", LocationUtil.getAroundLocations(Double.parseDouble(location[0]), Double.parseDouble(location[1]), 30,Float.parseFloat(range.toString())));
                }
            } catch (Exception e) {
                e.printStackTrace();
                return RestResponse.error("获取当前位置出错！");
            }
        }
        branchService.queryPage(map);
        return RestResponse.success();
    }

}
